<?php
class Settings_m extends MY_Model{
	
	function __construct(){
		parent::__construct();
		$this->_table = 'settings';
	}
	
	function get_all( $module , $type = NULL ){
		$this->db->order_by('ordering');
		$this->db->where('module', $module);
		if( $type )
			$this->db->where('type', $type);
		return parent::get_all();
	}
	function get_config( $module , $type = NULL ){
		$this->db->select('name,value');
		$this->db->where('module', $module);
		if( $type )
			$this->db->where('type', $type);
		$data = parent::get_all();
		//convert
		$result = new stdClass();
		foreach($data as $key => $value){
				$d = $value->name;
				$result->$d = $value->value;
		}
		return $result;
		
	}
	function update_list($module, $list){
//		print_r($list);exit;
		foreach($list as $key=>$value){
			$this->db->where('module',$module);
			$this->db->where('name',$key);
			$this->db->update($this->_table,array('value'=>$value));
//			echo $this->db->last_query();exit;
		}
	}
	
}